//
//  AppDelegate+UnitTestViewController.m
//  Customized
//
//  Created by AceWei on 2017/7/5.
//  Copyright © 2017年 陈凯旋. All rights reserved.
//

#import "AppDelegate+UnitTestViewController.h"
#import <MJExtension.h>
#import <React/RCTRootView.h>

@implementation AppDelegate (UnitTestViewController)


- (void)setupWindowRootViewController:(UIViewController *)vc
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    UINavigationController * naviC = [[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController = naviC;
    [self.window makeKeyAndVisible];
}


- (void)setupWindowRootViewController:(UIViewController *)vc
              hasNavigationController:(BOOL)hasNav
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    if (hasNav) {
        UINavigationController * naviC = [[UINavigationController alloc]initWithRootViewController:vc];
        self.window.rootViewController = naviC;
    } else {
        self.window.rootViewController = vc;
    }
    
    
    [self.window makeKeyAndVisible];
}


/// 返回字典或者数组
- (id)readJsonWithName:(NSString *)jsonName
{
    NSString *jsonStr = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonName ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];
    
    id data = [jsonStr mj_JSONObject];
    
    return data;
}



- (void)unitTestRN
{
    NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios"];
    
    RCTRootView *rootView =
    [[RCTRootView alloc] initWithBundleURL: jsCodeLocation
                                moduleName: @"MyReactNativeApp"
                         initialProperties:nil
                             launchOptions: nil];
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view = rootView;
    
    
    [self setupWindowRootViewController:vc hasNavigationController:NO];
}

@end
